import { Col, Form, Input, Modal, Row, Select } from 'antd';

const { TextArea } = Input;
const AddNewCurriculums = ({
  open,
  onCreate,
  onCancel,
  additionalInfor,
  role
}) => {

  const [form] = Form.useForm();
  const assessmentOptions = [
    { value: 1, label: '开卷', },
    { value: 2, label: '闭卷', },
    { value: 3, label: '考核', },
  ]
  const semesterOptions = [
    { value: 1, label: '大一上', },
    { value: 2, label: '大一下', },
    { value: 3, label: '大二上', },
    { value: 4, label: '大二下', },
    { value: 5, label: '大三上', },
    { value: 6, label: '大三下', },
    { value: 7, label: '大四上', },
    { value: 8, label: '大四下', },
  ]
  const typeOptions = [
    { value: 1, label: "必修" },
    { value: 2, label: "选修" }
  ]


  const items = [
    { name: "fd_teacNum", label: "教师", rules: {}, span: 12, labelSpan: 7, disable: true, wrapperCol: 16, options: additionalInfor.teacher, value: role.fd_idNum },
    { name: "fd_professionalNum", label: "专业", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16, options: additionalInfor.professionals },
    { name: "fd_curriculumNum", label: "课程代码", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16, },
    { name: "fd_curriculumName", label: "课程", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16 },
    { name: "fd_claNum", label: "班级", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16, options: additionalInfor.classes },
    { name: "fd_type", label: "课程类型", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16, options: typeOptions },
    { name: "fd_credit", label: "学分", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16 },
    { name: "fd_creditHours", label: "学时", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16 },
    { name: "fd_assessmentMethod", label: "考核方式", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16, options: assessmentOptions },
    { name: "fd_semester", label: "学期", rules: {}, span: 12, labelSpan: 7, disable: false, wrapperCol: 16, options: semesterOptions },
    { name: "fd_remarks", label: "备注", rules: {}, span: 24, labelSpan: 3, disable: false, wrapperCol: 21 },
  ]

  return (
    <Modal
      destroyOnClose
      width={550}
      open={open}
      okText="添加"
      cancelText="退出"
      onCancel={onCancel}
      onOk={() => {
        form
          .validateFields()
          .then((values) => {
            form.resetFields();
            onCreate(values);
          })
          .catch((info) => {
            console.log('Validate Failed:', info);
          });
      }}
    >
      <Form
        preserve={false}
        form={form}
        layout="inline"
        name="form_in_modal"
        className="updata-user-infor"
      >
        <Row gutter={18}>
          {
            items.map((item) => {
              return (
                <Col key={item.name} span={item.span} style={{ padding: "10px" }}>
                  <Form.Item
                    name={item.name}
                    label={item.label}
                    rules={[item.rules?.must]}
                    labelCol={{
                      span: item.labelSpan,
                    }}
                    wrapperCol={{
                      span: item.wrapperCol,
                    }}
                    initialValue={item.value}
                  >
                    {
                      ['fd_curriculumNum', 'fd_curriculumName', 'fd_credit', 'fd_creditHours'].includes(item.name) ?
                        <Input disabled={item.disable} /> :
                        item.name === 'fd_remarks' ?
                          <TextArea rows={4} /> :
                          <Select
                            disabled={item.disable}
                            options={item.options}
                            showSearch
                            filterOption={(input, option) =>
                              (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
                            }
                          />
                    }
                  </Form.Item>
                </Col>
              )
            })
          }
        </Row>
      </Form>
    </Modal>
  );
};
export default AddNewCurriculums